from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    """
    自定义用户模型
    """
    GENDER_CHOICES = (
        ('M', '男'),
        ('F', '女'),
        ('U', '未知'),
    )

    phone = models.CharField(max_length=11, unique=True, verbose_name='手机号', null=True, blank=True)
    avatar = models.ImageField(upload_to='avatars/', null=True, blank=True, verbose_name='头像')
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='U', verbose_name='性别')
    student_id = models.CharField(max_length=20, unique=True, null=True, blank=True, verbose_name='学号')
    school = models.CharField(max_length=100, null=True, blank=True, verbose_name='学校')
    major = models.CharField(max_length=100, null=True, blank=True, verbose_name='专业')
    grade = models.CharField(max_length=20, null=True, blank=True, verbose_name='年级')
    bio = models.TextField(null=True, blank=True, verbose_name='个人简介')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'user'
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

    def __str__(self):
        return self.username
